<?php

function Success($message = 'ok', $data = [], $code = 0, $statusCode = 200)
{
    $res = [
        'code' => $code,
        'message' => $message,
        'result' => $data,
    ];
    return response()->json($res, $statusCode);
}

function Error($message = 'error', $code = -1,  $data = [], $statusCode = 200)
{
    $res = [
        'code' => $code,
        'message' => $message,
        'result' => $data,
    ];
    return response()->json($res, $statusCode);
}

function uploadSuccess($message = 'ok', $url = [], $data = [], $code = 0, $statusCode = 200)
{
    $res = [
        'code' => $code,
        'message' => $message,
        'url' => $url,
        'result' => $data
    ];
    return response()->json($res, $statusCode);
}

/**
 * 生成用户安全密钥
 * @param int $length
 * @return string
 */
function GenerateSafeKey($length = 16)
{
    $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
    $safe_key = '';
    for ($i = 0; $i < $length; $i++) {
        $safe_key .= $chars[mt_rand(0, strlen($chars) - 1)];
    }
    return $safe_key;
}

